"use strict";
cc._RF.push(module, '096f3G0octBYZyrE6NnAuNL', 'ChooseStageJS');
// src/ChooseStageJS.js

"use strict";

var n = module.exports = {};
var t = module;

var i = require('GameDataManagerJS'),
    o = require('define');

cc.Class({
  "extends": cc.Component,
  properties: {
    m_MaxUnlockedStageIdx: 0,
    m_StageCount: 0,
    m_PageCount: 0,
    m_Package: 0,
    m_PageStageCount: o.MaxCustomsPass,
    subStagePrefab: {
      "default": null,
      type: cc.Prefab
    },
    subPackgePrefab: {
      "default": null,
      type: cc.Prefab
    },
    contextScrollView: {
      "default": null,
      type: cc.ScrollView
    },
    audioControl: {
      "default": null
    }
  },
  onLoad: function onLoad() {
    var e = cc.find("Canvas").getComponent(cc.Canvas);
    cc.winSize.width / cc.winSize.height <= (750 / 1334).designScreen ? (e.fitHeight = !1, e.fitWidth = !0) : (e.fitHeight = !0, e.fitWidth = !1),
    /*e.alignWithScreen(),*/
    this.init(), this.audioControl = cc.find("AudioControlNode").getComponent("AudioSourceControl");
  },
  init: function init() {
    this.m_Package = i.getInstance().getLatestPackage(), this.m_MaxUnlockedStageIdx = i.getInstance().getMaxUnlockedStage(this.m_Package), this.m_StageCount = i.getInstance().getStageCount(this.m_Package), this.m_PageCount = this.m_StageCount / this.m_PageStageCount, this.addStageBtn();
  },
  start: function start() {},
  addStageBtn: function addStageBtn() {
    for (var e = {
      stageId: 0,
      startNum: 0
    }, t = 0; t < this.m_StageCount; ++t) {
      e.stageId = t, e.startNum = i.getInstance().getCompleteStars(this.m_Package, t), this.m_MaxUnlockedStageIdx == t && (e.startNum = 0);
      var n = cc.instantiate(this.subStagePrefab);
      this.contextScrollView.content.addChild(n), n.getComponent("subStarTemplateJS").init(e);
      var o = new cc.Component.EventHandler();
      o.target = this.node, o.component = "ChooseStageJS", o.handler = "enterGameSceneCallback", o.customEventData = e.stageId, n.getComponent(cc.Button).clickEvents.push(o);
    }

    this.contextScrollView.scrollToPercentVertical(1, .1);
  },
  enterGameSceneCallback: function enterGameSceneCallback(e, t) {
    this.playClick();
    e.target.getComponent(cc.Button);
    var n = t;
    n <= this.m_MaxUnlockedStageIdx ? (console.log(" enterGameSceneCallback  unlcok =", n), this.playClick(), i.getInstance().setGameCurLevelNum(n), cc.director.loadScene("game")) : console.log(" enterGameSceneCallback lock =", n);
  },
  saveScrollPos: function saveScrollPos() {
    var e = this.contextScrollView.getContentPosition();
    i.getInstance().setStagePageScollPos(e);
  },
  _createPage: function _createPage() {},
  addSubPage: function addSubPage() {},
  playClick: function playClick() {
    this.audioControl && this.audioControl.playClick();
  }
});

cc._RF.pop();